/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.produce.data.controller;

import javax.servlet.http.HttpServletRequest;

import me.send.data.service.cons.AppDownloadHost;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author maxmin
 *
 * @date 2015年9月6日 下午7:40:21
 */
@Controller
@RequestMapping()
public class DownloadController {
	
	/**
	 * 根据前台请求的设备跳转到不同的下载地址
	 * 
	 * @param request
	 * @return
	 * @author maxmin
	 * @date 2015年9月7日下午4:53:23
	 */
	@RequestMapping(value="/download")
	public String toDownload(HttpServletRequest request) {
		String agent = request.getHeader("user-agent");
		int isIos = agent.toLowerCase().indexOf("iphone");
		int isAnd = agent.toLowerCase().indexOf("android");
		if (isIos>-1) {
			return "redirect:"+AppDownloadHost.IOS_DOWNLOAD_HOST;
		}
		if (isAnd>-1) {
			return "redirect:"+AppDownloadHost.ANDROID_DOWNLOAD_HOST+Math.random();
		}
		return "download";
	}
	
	/**
	 * 根据前台请求的设备跳转到不同的下载地址
	 * 
	 * @param request
	 * @return
	 * @author maxmin
	 * @date 2015年9月7日下午4:53:23
	 */
	@RequestMapping(value="/userdownload")
	public String toUserDownload(HttpServletRequest request) {
		String agent = request.getHeader("user-agent");
		int isIos = agent.toLowerCase().indexOf("iphone");
		int isAnd = agent.toLowerCase().indexOf("android");
		if (isIos>-1) {
			return "redirect:"+AppDownloadHost.IOS_USER_DOWNLOAD_HOST;
		}
		if (isAnd>-1) {
			return "redirect:"+AppDownloadHost.ANDROID_USER_DOWNLOAD_HOST+Math.random();
		}
		return "user_download";
	}
}
